﻿using System;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using ResumeSharp.Data;
using ResumeSharp.Properties;

namespace ResumeSharp
{
    public partial class UserProfileForm : Form
    {
        private ResumeSharpEntities db;
        private Account user;

        public UserProfileForm(ref Account acct)
        {
            InitializeComponent();
            user = acct;
        }
        private void UserProfileForm_Load(object sender, EventArgs e)
        {
            db = ((MainForm)this.MdiParent).Database;

            txtSurname.Text = user.Surname;
            txtName.Text = user.GivenName;
            cal.SetDate(user.DateOfBirth.Value);
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (user.IsNew)
            {
                db.AddToAccount(user);
                user.Id = Guid.NewGuid();
                user.IsNew = false;
            }

            db.SaveChanges();
            this.Close();
        }
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            user.GivenName = txtName.Text;
        }

        private void txtSurname_TextChanged(object sender, EventArgs e)
        {
            user.Surname = txtSurname.Text;
        }

        private void cal_DateChanged(object sender, DateRangeEventArgs e)
        {
            user.DateOfBirth = e.Start;
        }
    }
}
